package com.gxa.web_admin.controller;

import com.gxa.common.base.RespResult;
import com.gxa.modules.dto.LoginFormDTO;
import com.gxa.modules.service.SysUserService;
import com.gxa.web_admin.vo.SysUserVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
@Slf4j
@RestController
public class LoginController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/sulogin")
    public RespResult sulogin(LoginFormDTO loginFormDTO, HttpServletResponse response){
        return sysUserService.login(loginFormDTO,response);
    }

    @GetMapping("/logout")
    public RespResult logout(){
        Subject subject = SecurityUtils.getSubject();//admin kzz zss
        // 将Shiro中用户认证的信息清空--退出
        Object principal = subject.getPrincipal();
        subject.logout();
        log.info("{}用户退出了！！！",principal.toString());
        return RespResult.success();
    }

}
